package com.zys.principles.demo3.emps.emp3;

/**
 * 通过setter方法依赖传递
 */
public class emp3 {
    public static void main(String[] args) {
        ChangHong changHong = new ChangHong();
        OpenAndClose openAndClose = new OpenAndClose();
        openAndClose.setTv(changHong);
        openAndClose.open();
    }
}

class ChangHong implements ITV {
    @Override
    public void play() {
        System.out.println("长虹电视机打开了");
    }
}
    interface IOpenAndClose{
        public void open();
        public void setTv(ITV tv);
    }

    interface ITV{
        public void play();
    }

    class OpenAndClose implements IOpenAndClose{

        private ITV tv;
        @Override
        public void open() {
            this.tv.play();
        }

        @Override
        public void setTv(ITV tv) {
            this.tv = tv;
        }
    }


